(function(){
    function GetCustomFlow(){
        this.init(); 
    }
    GetCustomFlow.prototype = {
        constructor:GetCustomFlow,
        init:function(){
            this.nodata = '<tr><td  colspan="9">暂无信息</td></tr>';
            var _this = this;
            var _this = this;
            // 日历
            $.datetimepicker.setLocale('ch');
            $('#endtime').datetimepicker({
                format: 'Y-m-d',
                value:new Date().dateadd("d"),
                maxDate: new Date(),
                onChangeDateTime:function(dp,$input){
                    var limitStart = new Date($('#begintime').val().replace('-','/'));
                    var nowStart = new Date($('#endtime').val().replace('-','/'));
                    if(limitStart > nowStart){
                        $('#endtime').val(limitStart.format("YY-M-D"))

                    }
                },
                timepicker: false
            });
            
            $('#begintime').datetimepicker({
                format: 'Y-m-d',
                value:new Date().dateadd("d", -2),
                maxDate: new Date(),
                onChangeDateTime:function(dp,$input){
                    var limitStart = new Date($('#endtime').val().replace('-','/'));
                    var nowStart = new Date($('#begintime').val().replace('-','/'));
                    if(limitStart < nowStart){
                        $('#begintime').val(limitStart.format("YY-M-D"))
                    }
                },
                timepicker: false
            });
            // 中奖输入框控制
            $("#selzjLabel").unbind("click").click(function(){
                 var isChecked = $("#ischecked").prop("checked");
                 if( !isChecked )
                 {
                     $("#djiangMoney").prop("disabled", false);
                 }
                 else
                 {
                    $("#djiangMoney").prop("disabled", true);

                 }
            });
        
                this.getReportList(1);
            
                $("#searchBtn").unbind("click").click(function(){
                     _this.getReportList(1);
                });

                $.extend({page:function(pn){
                    _this.getReportList(pn);
                }});
         
        },
        getReportList:function( pn ){
            var _this = this;
            var isDajiang = $("#djiangMoney").val();
            var isWin = $("#ischecked").prop("checked");
            var stime = $("#begintime").val();
            var etime = $("#endtime").val();
            var searchBalance ='';
            var settle = $("#jiesuanstatus").val()+"";
            settle = settle ? "&settle="+settle : '';
            // 中奖金额 balance 不能为0 为空的时候 默认赋值0.1
            if( isWin )
            {
                searchBalance = isDajiang?"&balance="+isDajiang:'&balance=0.1';
            }
            $.ajax({
                type:"get",
                url:"/admin/proj?ps=20&pn="+pn+searchBalance+"&stime="+stime+"&etime="+etime+settle,
                dataType:"json",
                success:function( info ){
                    var code = info.code;
                    var desc = info.desc;
                    if( code == 1 )
                    {
                        var data = info.data;
                        var count = info.count;
                        var pageno = count.pn;
                        
                        if( data.length )
                        {
                            var gameTypeJson = {
                                "41":"胜平负",
                                "42":"上下单双",
                                "43":"进球数",
                                "44":"半全场",
                                "45":"比分"
                            };
                            var stateJson = {
                                "0":"已申请",
                                "1":"确认"
                            };
                            var settleJson = {
                                "0":"未结算",
                                "1":"已结算"
                            };
                            var strArr = [];
                            data.forEach(function( value, key  ){
                                var username  = value.username ;
                                var gameid = value.gameid;//彩种编号
                                var projid = value.projid;//订单编号
                                var settle = value.settle;//结算状态
                                var period = value.period;//期次
                                var promoney = value.money;//方案金额
                                var award = value.balance;//奖金
                                var state = value.state;
                                var orderTime = value.stime;//下单时间

                             
                                var trClass =  key%2 == 0 ? "even" : "odd";
                                var html = '<tr class="'+trClass+'"  >\
                                                <td>'+username+'</td>\
                                                <td>'+gameTypeJson[gameid]+'</td>\
                                                <td>'+projid+'</td>\
                                                <td>'+period+'</td>\
                                                <td>'+promoney+'</td>\
                                                <td>'+award+'</td>\
                                                <td>'+settleJson[settle]+'</td>\
                                                <td>'+orderTime+'</td>\
                                                <td>'+stateJson[state]+'</td>\
                                            </tr>';

                                    strArr.push( html );

                            });

                            $("#unticketList").html( strArr.join(""));
                          
                            
                            // 分页
                            var pn = count.pn;
                            var tp = count.tp;
                            var tr = count.tr;
                            $("#countpages").html( tp );
                            $("#countnums").html( tr );
        
                            var pageHtml = getPages(pn,tp, "$.page");

                            $("#paginationSel").html(pageHtml);

                        }
                        else
                        {
                            $("#unticketList").html(_this.nodata);

                        }

                    }
                    else
                    {
                       $.alert(code, desc);
                    }


                }
            });


        },
 
   
  
   
      
      
    };





  new GetCustomFlow();

}());